Skip to content

fix(ci): hash-pin the Python build backend the PyPI publish job executes - #362

Merged
jpr5 merged 1 commit into
mainfrom
drift/pin-publish-deps
Aug 6, 2026
Merged

jpr5 merged 1 commit into
mainfrom
drift/pin-publish-deps

Conversation

@jpr5

@jpr5 jpr5 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What

publish-release.yml's publish-pytest job carries environment: pypi and
id-token: write, and it is the job that publishes aimock-pytest to PyPI
through OIDC trusted publishing. It installed hatch by bare name from PyPI and
then ran it. The Python test matrix had the same shape with no wrapper at all.
Both now install a hash-pinned build backend and build with isolation off.

RED — measured, not reasoned about

Real pip, the committed step bodies run verbatim, only the registry
substituted (PIP_NO_INDEX=1 PIP_FIND_LINKS=<dir> — that directory is the entire
network, the pip analogue of stubbing curl).

INSTALL_STEP_EXIT=0     Successfully installed hatch-99.0.0
BUILD_STEP_EXIT=0       SUBSTITUTED-PACKAGE-EXECUTED
=== MARKER ===          SUBSTITUTED hatch ran argv=build

Both steps reported success and the substituted package executed, beside the
publish identity. test-pytest.yml's one-liner imported a substituted
hatchling.build twice — get_requires_for_build_wheel, then metadata
preparation — before pip did anything else.

Pinning hatch would NOT have closed it

hatch build builds in an isolated environment and resolves this project's
build-system.requires (hatchling) from PyPI at build time, unpinned — the
same pinned-wrapper / unpinned-payload shape install.sh had. Against an empty
index:

× No solution found when resolving dependencies:
╰─▶ Because hatchling was not found in the package registry ...

python -m hatchling build against the same empty index exits 0. It fetches
nothing.

So the smallest sound option is to pin the backend and build without
isolation: 6 requirements / 57 hashes, versus 44 packages / 331 hashes for
hatch — smaller and the one that actually closes the hole.

The published artifacts do not change. hatch build and
python -m hatchling build produced byte-identical sdist and wheel at 0.5.2:
29ac7b3a…2c35 (wheel) and 0a54957b…8580 (sdist); diff -r over both
unpacked: no differences.

GREEN

INSTALL_STEP_EXIT=1
ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. ...
        Expected sha256 6b48ad40…16b
        Expected     or aac80bec…544
             Got        020753a326173b84ee56d81bba1255beb8b7dc15e0731618a94e6c53e5616bdf
BUILD_STEP_EXIT=1       No module named hatchling
=== MARKER (must be absent) ===  No such file or directory

The refusal is the demonstrated absence of the payload at an interpreter, not
an inference from an exit code. Under GitHub's exact default shell flags
(bash --noprofile --norc -e -o pipefail) the test-matrix body fails closed —
its second line never runs.

Positive control, genuine bytes, fully offline: install exit 0, build exit 0,
artifacts byte-identical to what hatch build produces. On Python 3.10 and 3.13
the matrix body also succeeds (3.10 pulls tomli via its marker, 3.13 does not)
and import aimock_pytest, pytest, requests works.

Hashes

Three independent sources agree, none taken on trust: uv pip compile --generate-hashes; PyPI's JSON API, matched hash-by-hash (57/57, no extras,
none missing); and sha256 of the bytes pip download --require-hashes
actually fetched.

The publish gate is intact — an unchanged-version push publishes NOTHING

No if:, needs:, or id: line changed. Both gates were run verbatim against
the live registries, read-only, no credential in the environment:

npm view @copilotkit/aimock@1.38.0                       -> published=true  => `publish` job SKIPPED
pip install "aimock-pytest==0.5.2" --dry-run --no-deps   -> published=true  => Build + Publish steps SKIPPED

The second was run after --require-hashes in the same environment — direct
evidence that hash-pinning does not poison the probe. That is also why
--require-hashes is scoped to the one install and not set job-wide: the probe's
failure means "not published yet", so a hash-gated probe would fail for an
unrelated reason and publish unconditionally. Both gates still discriminate
(a bogus version returns published=false on both sides).

publish-release.yml was not renamed or moved — trusted publishing is bound
to the workflow filename. It has no pull_request trigger, so this PR cannot
publish. No workflow was dispatched and no run re-run.

Guard suite — src/__tests__/publish-pin-workflow.test.ts, 9 tests

Seven static, two EXECUTE real pip against the repo's own pin file. The executed
pair matches pip's tamper message rather than an exit code, since a non-zero exit
cannot distinguish a hash refusal from any other error. A separate test throws
when CI is set
if no python3 -m pip exists — a skipped guard in CI proves
nothing.

RE-BREAK — 7 mutations, each applied, run, restored; all touched files
md5-identical before and after:

mutation test red
install step back to pip install hatch installs its build backend from a hash-pinned requirements file
build step back to hatch build the build re-fetches nothing: no build-isolating builder
hatchling loses its --hash lines the pin file is a real hash pin and SUBSTITUTED backend bytes are REFUSED
PIP_REQUIRE_HASHES set job-wide hash checking is scoped to the install
the PyPI publish step loses its if: both publishing steps stay conditioned on that gate
test matrix re-enables build isolation the Python test matrix installs from the same pin
positive control given a wrong digest POSITIVE CONTROL: bytes whose sha256 IS listed clear the hash gate

Still unpinned after this PR — named, not glossed

  • requests / pytest in test-pytest.yml — deliberate. That job exists to
    catch breakage against current releases and holds no secret (contents: read,
    zero secrets. references). Pinning them was compiled and measured
    (17 requirements, 170 hashes) and rejected for the coverage loss, not effort.
  • publish-commit.yml:20 npx pkg-pr-new publish — not in package.json,
    not in the lockfile, so npx fetches latest. Another agent owns that file.
  • pnpm/action-setup — pnpm resolved at the packageManager version with no
    integrity hash beside it. Another agent owns the toolchain.
  • publish-release.yml's pip install … --dry-run --no-deps probe installs
    nothing and executes no downloaded code; hash-gating it would break the gate
    open.

Every uses: in both changed files is pinned to a 40-hex commit SHA.

Gates

pnpm build 0 · pnpm test 0 (5075 passed, 173 files, +9 all in the new
file) · pnpm test:drift 0 · tsc --noEmit 0 · pnpm lint 0 ·
pnpm test:exports 0 · prettier clean · zizmor --min-severity medium 0 ·
bash -n on 21 run: bodies, 0 failures · commitlint 0.

actionlint reports one pre-existing info (SC2086 on >> $GITHUB_ENV,
identical on origin/main). A second pre-existing info — SC2102 on the
unquoted [test] extras — is gone, quoted while editing that line.

None of the named pre-existing flakes (proxy-buffer-cap, ws-framing,
timing-recording) appeared.

Scope

Exactly .github/requirements/hatchling.txt,
.github/workflows/publish-release.yml, .github/workflows/test-pytest.yml,
src/__tests__/publish-pin-workflow.test.ts. No package.json, CHANGELOG.md,
.claude-plugin/*, charts/*, packages/aimock-pytest/* or pnpm-lock.yaml.
No version consumed. packages/aimock-pytest was copied to scratch for every
build; the tree's copy was never written to.

This PR touches src/**, so test-pytest.yml runs on it and exercises the new
install path across 3.10–3.13 × Node 20/22/24 — which is the point. It matches
none of test-drift.yml's paths:, so the credit-spending drift-live-pr job
does not fire.

`publish-release.yml`'s `publish-pytest` job carries `environment: pypi` and
`id-token: write`, and it is the job that publishes aimock-pytest to PyPI
through OIDC trusted publishing. It installed `hatch` by bare name from PyPI
and then ran it. Measured, not reasoned about: with the registry serving
substituted bytes, `pip install hatch` installed them (exit 0) and
`hatch build` EXECUTED them (exit 0), beside the publish identity.

Pinning `hatch` would not have closed it. `hatch build` builds in an ISOLATED
environment and resolves this project's `build-system.requires` — hatchling —
from PyPI at build time, unpinned: the same pinned-wrapper / unpinned-payload
shape the Ollama installer had. Against an empty index, `hatch build` dies with
"hatchling was not found in the package registry".

So the backend itself is hash-pinned in `.github/requirements/hatchling.txt`
(6 requirements, `==`-pinned, sha256-hashed, universal across 3.10-3.13) and
the build invokes it directly with no isolation, fetching nothing. `hatch
build` and `python -m hatchling build` produce byte-identical sdist and wheel
for this package at 0.5.2, so the published artifacts do not change.

`test-pytest.yml` had the same hole with no wrapper at all: the substituted
`hatchling.build` was imported twice before pip did anything else. It now
installs from the same pinned file and builds with isolation off. Its runtime
and test dependencies (requests, pytest) are still resolved unpinned, on
purpose — that job exists to catch breakage against current releases and holds
no secret; freezing them would retire the signal.

`--require-hashes` is scoped to the one install invocation. Job-wide it would
also hit the already-published probe, whose FAILURE means "not published yet",
so a hash-gated probe would fail for the wrong reason and publish
unconditionally. A guard asserts that scope, and that both publishing steps
stay conditioned on the probe.
@pkg-pr-new

pkg-pr-new Bot commented Aug 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@copilotkit/aimock@362

commit: 9b8898c

@jpr5
jpr5 marked this pull request as ready for review August 6, 2026 03:50
@jpr5
jpr5 merged commit 55239d5 into main Aug 6, 2026
26 checks passed
@jpr5
jpr5 deleted the drift/pin-publish-deps branch August 6, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant